const mongoose = require('mongoose')
const mongoosePaginate = require('mongoose-paginate')
const path = require('path')

module.exports = function (db) {
    return db.model(path.basename(__filename, path.extname(__filename)), new mongoose.Schema(
        {
            id: {
                type: String,
                unique: true,
                required: true,
                index: true,
            },

            service_info: {
                app_name: String,
                app_key: String,
            },

            // 接收者 user_ids
            notice_receiver: [String],

            // 用户单位，用户统计单位发送量
            org_id: {
                type: String,
                index: true,
            },

            // 下发通知方式
            way: {
                provider_code: String,
                way_code: {
                    type:String,
                    index: true,
                },
                template_code: String,
                template_code_rel: String,
                sign_name: String,

                app_key: String,
                app_secret: String,
            },

            // 消息内容 类型 1=文本，2=JSON,3=图片，4=声音，5=视频, 6=设备事件
            content_type: {
                type: Number,
                index: true,
                default: 1,
            },

            content: mongoose.Schema.Types.Mixed,

            //创建时间
            created_at: {
                type: Date,
                index: true,
                default: Date.now
            },

            updated_at: {
                type: Date,
                default: Date.now
            },

            status: {  // 1=初始化，2=处理完成
                type: Number,
                default: 1,
            }
        },
        {
            collection: path.basename(__filename, path.extname(__filename)),
            timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }
        }).plugin(mongoosePaginate)
    )
}
